package leetcode_数组.matrix;

/**
 * 旋转图像
 * 算法：模拟
 * 旋转可以由翻转得到
 * 顺时针旋转 90° = 水平 + 左斜对角 (不分先后)
 *
 * @author origin
 */
public class _48 {

    public void rotate(int[][] matrix) {
        int n = matrix.length;
        // 先水平(左右)翻转
        for (int i = 0; i < n / 2; i++) {
            for (int j = 0; j < n; j++) {
                int tem = matrix[i][j];
                matrix[i][j] = matrix[n - i - 1][j];
                matrix[n - i - 1][j] = tem;
            }
        }
        // 再对角(左斜线)翻转
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < i; j++) {
                int tem = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = tem;
            }
        }
    }

}
